package com.kjtpay.design_pattern.singleton;

/**
 * 双重检验锁方式的单例类
 */
class DoubleCheckSingleton {
    // 定义单例静态变量
    private volatile static DoubleCheckSingleton instance = null;

    // 构造函数私有化
    private DoubleCheckSingleton() {}

    // 获取单例对象方法
    public static DoubleCheckSingleton getInstance() {
        if (instance == null) {
            synchronized (DoubleCheckSingleton.class) {
                if (instance == null) {
                    instance = new DoubleCheckSingleton();
                }
            }
        }
        return instance;
    }
}
